// import {
//     selectButtonInfoById,
//     editButtonInfo,
//     deleteButtonInfoByIds,
//     searchButtonInfoBy,
// } from "../../api/template"


// import {
//     // typeOf,
//     listFormat
// } from '@/libs/util'

// 标题
const homeConfig1 = function () {
    return {
        name: undefined,
        coverPhoto: undefined,
        color: "rgb(0, 77, 161)",
    }
}
// 轮播图
const homeConfig2 = function () {
    return {
        itemHeight: 200,
        // linkUrl: undefined,
        itemImg: [],
    }
}
// 图片
const homeConfig7 = function () {
    return {
        itemImg: [],
    }
}
// 视频
const homeConfig8 = function () {
    return {
        itemVideo: undefined,
    }
}


// 工厂数据
const getFactoryForm = () => {
    return {
        id: 0,
        factoryCode: '',
        factoryName: '',
        logisticsPwd: '',
        erp: '',
        status: 0,
        remark: ''
    }
}



const h5template = {
    state: {
        homeConfig1: homeConfig1(),
        homeConfig2: homeConfig2(),
        homeConfig7: homeConfig7(),
        homeConfig8: homeConfig8(),
    },
    mutations: {
        SET_HOME_MSG1: (state, data = homeConfig1()) => {
            const {
                homeConfig1
            } = state
            for (const key in data) {
                if (key in homeConfig1) {
                    homeConfig1[key] = data[key]
                }
            }
            // state.homeConfig1 = msg
        },
        SET_HOME_MSG2: (state, data = homeConfig2()) => {
            const {
                homeConfig2
            } = state
            for (const key in data) {
                if (key in homeConfig2) {
                    homeConfig2[key] = data[key]
                }
            }
            // state.homeConfig1 = msg
        },
        SET_HOME_MSG7: (state, data = homeConfig7()) => {
            const {
                homeConfig7
            } = state
            for (const key in data) {
                if (key in homeConfig7) {
                    homeConfig7[key] = data[key]
                }
            }
        },
        SET_HOME_MSG8: (state, data = homeConfig8()) => {
            const {
                homeConfig8
            } = state
            for (const key in data) {
                if (key in homeConfig8) {
                    homeConfig8[key] = data[key]
                }
            }
        },
        // 工厂
        setFactoryForm(state, data = getFactoryForm()) {
            const {
                factoryForm
            } = state
            for (const key in data) {
                if (key in factoryForm) factoryForm[key] = data[key]
            }
        },
        RESET_MSG_ALL: (state) => {
            state.homeConfig1 = homeConfig1()
            state.homeConfig2 = homeConfig2()
            state.homeConfig7 = homeConfig7()
            state.homeConfig8 = homeConfig8()
        },
        RESET_MSG_ONE: (state, data) => {
            // debugger
            state[`homeConfig${data}`] = `homeConfig${data}`()
            // state.homeConfig1 = homeConfig1()
        },
    },
    actions: {
        // 删除模板
        deleteButtonInfoByIds({
            state,
            dispatch
        }, data) {
            return deleteButtonInfoByIds(data).then((res) => {
                res && dispatch('list/getList', undefined, {
                    root: true
                })
                // dispatch('fetchFactoryNameList', true)
                return res
            })
        },
        // 提交模板
        editButtonInfo({
            state,
            dispatch
        }, data) {
            return editButtonInfo(data).then((res) => {
                res && dispatch('list/getList', undefined, {
                    root: true
                })
                // dispatch('fetchFactoryNameList', true)
                return res
            })
        },
    },
}
export default h5template
